function random_shuffle(tbl, n)
    local n = math.min(#tbl, n)
    if n <= 0 then
        return {}
    end

    local t = {}
    for i = 1, #tbl do
        table.insert(t, { pos = i, weight = math.random(10000) })
    end
    table.sort(t, function(a, b) return a.weight < b.weight end)

    local res = {}
    for i = 1, n do
        local pos = t[i].pos
        table.insert(res, tbl[pos])
    end
    return res
end
